//
//  HKAggrementView.m
//  HKTimeKitApp
//
//  Created by huzhaoke1 on 2023/7/22.
//

#import "HKAggrementView.h"
#import "HKNavigationBar.h"
#import "UIView+properties.h"
#import <Masonry/Masonry.h>
#import "HKRequestDefine.h"

@implementation HKAggrementView

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
     
        self.backgroundColor = [[UIColor grayColor] colorWithAlphaComponent:0.3];
        
        CGFloat top = [HKNavigationBar naviBarHeight] + 20;
        UIView *bgView = [[UIView alloc] initWithFrame:CGRectMake(24, top, self.frame.size.width - 48, self.frame.size.height - top - 20)];
        bgView.layer.cornerRadius = 5;
        bgView.layer.masksToBounds = YES;
        bgView.backgroundColor = [UIColor whiteColor];
        [self addSubview:bgView];
        [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(top);
            make.width.mas_equalTo(self).offset(-48);
            make.centerX.mas_equalTo(self);
            make.height.mas_equalTo(self).offset(-top - 20 - 40);
        }];
        
        UITextView *textView = [[UITextView alloc] initWithFrame:CGRectZero];
        [self addSubview:textView];
        
        [textView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(bgView.mas_top).offset(40);
            make.centerX.mas_equalTo(bgView);
            make.width.mas_equalTo(bgView).offset(-80);
            make.height.mas_equalTo(bgView).offset(-180);
        }];
        
        //创建初始化文本的颜色，以及字体大小
        NSDictionary *dictionary = @{NSFontAttributeName:[UIFont systemFontOfSize:17],NSForegroundColorAttributeName:[UIColor blackColor]};

        NSString * string = @"我们非常重视您的用户权益与个人信息的保护，在您使用本APP服务前，请充分阅读并理解以下说明：\n\n1、为保障我们平台的安全和正常运营，我们可能会申请一些系统权限来收集您的设备信息，包括但不限于IMEI、IMSI、设备MAC地址等。这些信息将用于平台安全风控，以保护您的账户和数据安全。\n\n2、其他必要权限说明：为了更完善地体验本应用完整功能，请授予本应用相册读写、摄像头、麦克风、系统日历、通知等权限。\n特别说明，应用常驻通知栏是为了更好的进行提醒推送服务，请勿关闭此项通知，以免被试错过重要的消息和事件提醒环节，应用程序本身不会占用太多的系统内存和资源，请再次放心，并且将应用加入清理后台白名单中以保证推送通道的活跃。\n\n请您理解，我们收集这些权限的目的仅为了提供更好、更安全、更个性化的服务体验。我们承诺严格遵守相关法律法规，妥善保护您的个人信息，并且不会将您的信息用于任何未经授权的用途。\n\n在使用本APP服务之前，请务必详细阅读并理解我们的《用户协议》和《隐私政策》，以便您充分了解您的权益和我们的信息处理方式。如果您对其中的条款有任何疑问，请随时联系我们，我们将乐意解答您的问题。\n\n点击同意按钮，即表示您已阅读、理解并同意遵守以上说明和相关协议；如果您不同意，则退出App。\n\n感谢您的理解与支持！\n\n【时间锦囊】团队";
        //创建富文本
        NSMutableAttributedString *attributeStr = [[NSMutableAttributedString alloc] initWithString:string attributes:dictionary];
        //实现文本链接
        ;
        [attributeStr addAttribute:NSLinkAttributeName value:LINK_BASE_WEB_URL(@"protocol?type=1") range:[string rangeOfString:@"隐私政策"]];
        [attributeStr addAttribute:NSLinkAttributeName value:LINK_BASE_WEB_URL(@"protocol?type=2") range:[string rangeOfString:@"用户协议"]];
        textView.tintColor = [UIColor blueColor];//调节文本链接字体的颜色
        textView.attributedText = attributeStr;
        textView.editable = NO;
        
        UIButton *aggreButton = [[UIButton alloc] initWithFrame:CGRectZero];
        [aggreButton setTitle:@"同意" forState:UIControlStateNormal];
        [aggreButton.titleLabel setFont:[UIFont systemFontOfSize:16]];
        [aggreButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [aggreButton setBackgroundColor:[UIColor blueColor]];
        aggreButton.layer.cornerRadius = 20;
        aggreButton.layer.masksToBounds = YES;
        [self addSubview:aggreButton];
        self.aggreeButton = aggreButton;
        
        [aggreButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(textView.mas_bottom).offset(20);
            make.height.mas_equalTo(40);
            make.width.mas_equalTo(textView);
            make.centerX.mas_equalTo(textView);
        }];
        
        UIButton *cancelButton = [[UIButton alloc] initWithFrame:CGRectZero];
        [cancelButton setTitle:@"不同意，退出" forState:UIControlStateNormal];
        [cancelButton.titleLabel setFont:[UIFont systemFontOfSize:16]];
        [cancelButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [cancelButton setBackgroundColor:[UIColor whiteColor]];
        cancelButton.layer.cornerRadius = 20;
        cancelButton.layer.masksToBounds = YES;
        [cancelButton addTarget:self action:@selector(onTapCancel:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:cancelButton];
        
        [cancelButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(aggreButton.mas_bottom).offset(20);
            make.height.mas_equalTo(40);
            make.width.mas_equalTo(aggreButton);
            make.centerX.mas_equalTo(aggreButton);
        }];
    }
    return self;
}
- (void)onTapCancel:(id)sender {
    exit(0);
}


@end
